<?php
    include('header.php');
    
    $sql = 'SELECT * FROM news WHERE news_id='.$_GET['news_id'];
    $result = $db->Execute($sql);
    if($result->RecordCount()>0){
        
        if(img_exists(APPPATH.'/images/news',$result->fields['news_img'])){
            $img = '<img src="'.SITEURL.'/images/news/'.$result->fields['news_img'].'" /><input type="hidden" name="img_old" value="'.$result->fields['news_img'].'" /><br />';
        }else{
            $img = '<input type="hidden" name="img_old" value="" />';
        }
	
	$news_date = date('m/d/Y',$result->fields['news_date']);
	
	$select1 = '';
	$select2 = '';
	$select3 = '';
	
	switch($result->fields['news_video_pos']){
	    case 1:
		$select1 = 'selected="selected"';
		break;
	    case 2:
		$select2 = 'selected="selected"';
		break;
	    case 3:
		$select3 = 'selected="selected"';
		break;
	}
?>
    <div class="grid_24" id="contents">
        
        <div id="contents_">
            <form action="?m=news&s=news-edit_query" method="post" enctype="multipart/form-data">
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>หัวข้อ : </p>
                <input type="text" name="news_title" class="input medium" value="<?php echo $result->fields['news_title']; ?>" />
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>สถานที่ : </p>
                <input type="text" name="news_location" class="input medium" value="<?php echo $result->fields['news_location']; ?>" />
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>วันที่ : </p>
                <input type="text" name="news_date" class="input medium date_picker" value="<?php echo $news_date; ?>" />
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>ข้อความด้านบน : </p>
                <textarea class="styled_textarea large height120" name="news_msg_1"><?php echo $result->fields['news_msg_1']; ?></textarea>
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>ข้อความด้านล่าง : </p>
                <textarea class="styled_textarea large height120" name="news_msg_2"><?php echo $result->fields['news_msg_2']; ?></textarea>
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>วิดีโอ : </p>
                <p class="guideline">เช่น http://youtu.be/2jk4pJQ3_R4</p>
                <input type="text" name="news_video" class="input large" value="<?php echo $result->fields['news_video']; ?>"/>
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>ตำแหน่งวิดีโอ : </p>
                <select name="news_video_post" class="select input">
                    <option value="1" <?php echo $select1; ?>>ด้านบน</option>
                    <option value="2" <?php echo $select2; ?>>ตรงกลาง</option>
                    <option value="3" <?php echo $select3; ?>>ด้านล่าง</option>
                </select>
            </div>
            <div id="about_us_company_msg_1_th" class="form_field">
                <p>รูปประกอบ : </p>
                <p class="guideline">ขนาด 254x134 pixel</p>
		<?php echo $img; ?>
                <input type="file" name="news_img" class="input large" />
            </div>
            
            <div id="about_us_company_msg_2_en" class="form_field">
		<input type="hidden" name="news_id" value="<?php echo $result->fields['news_id']; ?>" />
                <button class="button">SAVE</button>
                <!--<div class="button" onclick="window.location='?m=services&s=packing-dyntecdisc-product'">CANCEL</div>-->
            </div>
            </form>
        </div>
        
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?php
    }else{
?>
    <div class="grid_24" id="contents">
        <div id="query_result">
        <?php
            echo 'ไม่มีข้อมูล <img src="images/ajax-loader.gif" />';
            redirect('?m=news',3);
        ?>
        </div>
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?php
    }
    include('footer.php');
?>
<script type="text/javascript">
    $(document).ready(function(){
        $('.date_picker').datepicker({
            'dateFormat':'mm/dd/yy',
            changeMonth: true,
	    changeYear: true
        }); 
    });
</script>